package com.ggdog.blog.DAO;


import com.ggdog.blog.POJO.Administrator;

import com.ggdog.blog.POJO.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserDAO {
    @Select("select *from User where userName=#{userName}")
    User findUserByName(String userName);
    @Insert("insert into User(userName,userPsd,status,createTime,updateTime) values (#{userName},#{md5Psd},0,now(),now())")
    void addUser(String userName, String md5Psd);
    @Select("select *from Administrators where userId=#{userId}")
    Administrator findAdminByUserId(int userId);
    @Select("select *from User")
    User[] getAllUser();
    @Update("UPDATE User SET userName = #{newName},status=#{status} WHERE id = #{id}")
    int updateUserById(int id, String newName,int status);
    @Update("update User set status=1 where id=#{id}")
    int deleteUserById(int id);
    @Select("select *from User where id=#{id}")
    User getUserById(int id);
    @Update("update User set avatarUrl=#{url} where id=#{id}")
    int updateUserAvatarUrlByUID(int id,String url);
    @Update("update User set userPsd=#{newPsd} where id=#{uid}")
    int updateUserPsdById(int uid, String newPsd);
    @Update("update Administrators set administratorCategory=#{newPermission} where userId=#{uid}")
    int updateAdminPermission(int uid, int newPermission);
    @Select("select * from Administrators")
    List<Administrator> getAllAdmin();
    @Delete("DELETE FROM Administrators WHERE administratorid = #{adminId}")
    int deleteAdminByAdminId(int adminId);
    @Insert("insert into Administrators(userId,administratorCategory) values (#{uid},#{permission})")
    int addNewAdminById(int uid,int permission);



}
